﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#endregion


namespace ESF.General.MVP
{
	public abstract class BaseEditPresenter<I, O> : BasePresenter<I> where I : IBaseEditViewer
	{
		#region Funciones
		
		public abstract O Get ();
		
		public abstract void Load (O pItem);
		
		public abstract void Save ();
		
		public virtual void Delete () { }
		
		public virtual new void Clear ()
		{
			_Viewer.CreationDateTime = null;
			_Viewer.ItemID = null;
			_Viewer.LastUpdateDateTime = null;
			_Viewer.UserCreationAlias = _Viewer.frmUserAlias;
			_Viewer.UserLastUpdateAlias = string.Empty;
		}		
		
		public virtual void PrepareFields () {}

		public override void Load()
		{
			O item;
			
			
			PrepareFields ();
			
			if (_Viewer.ItemID != null)
			{			
				item = Get ();
				
				if (item == null)
				{
					_Viewer.frmInfoMsg = string.Format ("El elemento identificado con {0} no existe", _Viewer.ItemID);
				}
			
				Load (item);
			}
			else
			{
				Clear ();
			}
		}
		
		#endregion
		
		
		#region Constructor
		
		public BaseEditPresenter (I pViewer) : base (pViewer) {}
		
		#endregion
	}
}
